package com.ztools.pc.controller.store;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ztools.common.model.pc.store.Category;
import com.ztools.common.util.common.PageUtil;
import com.ztools.common.util.common.Result;
import com.ztools.pc.service.store.CategoryService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:一口香菜
 * @Date: 2023/3/26  11:26
 * @Version 1.0
 */
@RestController
@RequestMapping("/store/category")
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    @RequestMapping("/list")
    public Result findList(@RequestBody PageUtil<Category> pageUtil) {
        Page<Category> list = categoryService.findList(pageUtil);
        return list != null ? Result.success("查询成功").data(list) : Result.error();
    }

    @RequestMapping("/delete")
    public Result delete(@RequestBody Category category) {
        boolean b = categoryService.delete(category);
        return b ? Result.success("删除成功") : Result.error();
    }

    @RequestMapping("/add")
    public Result add(@RequestBody Category category) {
        boolean b = categoryService.save(category);
        return b ? Result.success("添加成功") : Result.error();
    }

    @RequestMapping("/update")
    public Result update(@RequestBody Category category) {
        boolean b = categoryService.update(category);
        return b ? Result.success("修改成功") : Result.error();
    }

    @RequestMapping("/findByObject")
    public Result findByObject(@RequestBody Category category) {
        List<Category> list = categoryService.findByObject(category);
        return list != null ? Result.success("查询成功").data(list) : Result.error();
    }

}
